from common.base.base_handler import BaseHandler
from services.services_module.model import ServicesModule
from services.services_module.schemas.configs import GsmConfig, LteConfig, Telemetry, ModuleType
from settings import settings


class ServicesModuleHandler(BaseHandler):
    __slots__ = ['model']

    async def handle_set_lte_config(self, params: dict) -> bool:
        index, config = params['index'], LteConfig(**params['config'])
        self.model.lte_configs[index] = config
        self.model.lte_configure(index, config)

        return True

    async def handle_set_gsm_config(self, params: dict) -> bool:
        index, config = params['index'], GsmConfig(**params['config'])
        self.model.gsm_configs[index] = config
        self.model.gsm_configure(index, config)

        return True

    async def handle_get_all_lte_configs(self) -> list[LteConfig]:
        return self.model.lte_configs

    async def handle_get_lte_config(self, params: dict) -> LteConfig:
        index = params['index']
        return self.model.lte_configs[index]

    async def handle_get_all_gsm_configs(self) -> list[GsmConfig]:
        return self.model.gsm_configs

    async def handle_get_gsm_config(self, params: dict) -> GsmConfig:
        index = params['index']
        return self.model.gsm_configs[index]

    async def handle_get_all_module_types(self) -> list[str]:
        return self.model.module_type

    async def handle_get_module_type(self, params: dict) -> str:
        index = params['index']
        return self.model.module_type[index]

    async def handle_get_all_telemetry(self) -> list[Telemetry]:
        return self.model.telemetry

    async def handle_get_telemetry(self, params: dict) -> Telemetry:
        index = params['index']
        return self.model.telemetry[index]

    def __init__(self):
        self.model = ServicesModule()

        super(ServicesModuleHandler, self).__init__(request_queue_uuid=settings.SERVICES_MODULE_REQUEST_QUEUE)

        self.handle('get_module_type', self.handle_get_module_type)
        self.handle('get_all_module_types', self.handle_get_all_module_types)
        self.handle('set_lte_config', self.handle_set_lte_config)
        self.handle('get_lte_config', self.handle_get_lte_config)
        self.handle('get_all_lte_configs', self.handle_get_all_lte_configs)
        self.handle('set_gsm_config', self.handle_set_gsm_config)
        self.handle('get_telemetry', self.handle_get_telemetry)
        self.handle('get_all_telemetry', self.handle_get_all_telemetry)
        self.handle('get_gsm_config', self.handle_get_gsm_config)
        self.handle('get_all_gsm_configs', self.handle_get_all_gsm_configs)
